/* 
 * File:   FullLibrary.h
 * Author: sergey
 *
 * Created on 3 Декабрь 2009 г., 23:55
 *
 * FullLibrary - это библиотека, которая хранит все сложности функций подряд.
 * Эта информация хранится в 4-битовом представлении.
 */

#ifndef _FULLLIBRARY_H
#define	_FULLLIBRARY_H
#include <vector>
#include "LibraryInterface.h"

template <typename LIBINFO>
class FullLibrary:public LibraryInterface {
public:
    FullLibrary() {
        this->data.resize(LIBINFO::fC >> 1);        
        this->reset();
    }
    ~FullLibrary() { }
    inline void get(const UInt64 f, UInt8 &s) {
        const UInt8 ffs = data[f >> 1];
        s = (f & 1) == 0 ?  ffs >> 4 : ffs & 15;
    }
    inline void set(const UInt64 f, const UInt8 s) {
        const UInt8 ffs = data[f >> 1];
        data[f >> 1] = ((f & 1) == 0) ? (ffs & 15) ^ (s << 4) : (ffs & (15 << 4)) ^ s;
    }
    inline bool isSet(const UInt64 f) {
        return (f & 1 == 0 ? data[f >> 1] >> 4 : data[f >> 1] & 15) != 0;
    }
    void load(const std::string filename) {
        this->readFileOpen(filename.c_str());
        this->readIntVector(data, data.size());
        this->readFileClose();
    }
    void save(const std::string filename) {
        this->writeFileOpen(filename.c_str());
        this->writeIntVector(data);
        this->writeFileClose();
    }

private:
    std::vector<UInt8> data;

};

#endif	/* _FULLLIBRARY_H */

